/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */
package cn.reg;

import java.util.HashSet;
import java.util.Random;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * <p>Project: jse2302 - Ex7
 * <p>Powered by webrx On 2023-06-21 11:36:32
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Ex7 {
    public static void main(String[] args) {
        int nn = 0;
        Set<String> set = new HashSet<>();
        while (true) {
            ++nn;
            //获取随机的字符串表达式
            String str = str();

            //计算表达式的结果看是不是100
            //正则表达式，是一个特殊的字符串，功能是匹配 提取 替换 ?代表{0,1} . * + ?
            Pattern pattern = Pattern.compile("-?\\d+");
            Matcher m = pattern.matcher(str);
            int sum = 0;
            while (m.find()) {
                String n = m.group();
                sum += Integer.parseInt(n);
            }
            if (sum == 100) {
                set.add(str);
            }

            if (set.size() == 11) break;
        }

        for(String s : set){
            System.out.println(s + "=100");
        }


    }

    /**
     * Description: 返回一个字符串1-9随机放+-
     *
     * @date: 2023/6/21 11:41
     * @params: []
     * @return: java.lang.String
     */
    public static String str() {
        StringBuilder sbu = new StringBuilder();
        Random rand = new Random();
        String[] ps = {"", "+", "-"};
        for (int i = 1; i < 9; i++) {
            int len = ps.length;
            int pos = rand.nextInt(len); //取值随机 0 1 2
            String p = ps[pos];
            sbu.append(i + p);
        }
        sbu.append(9);
        return sbu.toString();
    }
}
